package com.googlecode.intellimars.sabotter;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;

// Suittarから拝借
public class Conv {
    public static String utc2jst(String utcString) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        return sdf.format(utc2Date(utcString));
    }

    public static Date utc2Date(String utcString) {
        //Parse DateTime String 2 Date
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);
        Date utcDt = sdf.parse(utcString,new ParsePosition(0));

        //set UTC Time
        GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        calendar.setTimeInMillis(utcDt.getTime());

        //to LocalTime
        calendar.setTimeZone(TimeZone.getDefault());

        return calendar.getTime();
    }
}
